package net.pimpas.web.jsf.components.tree;

import javax.faces.context.FacesContext;

import net.pimpas.web.jsf.components.UIComponentPimpasBase;
import net.pimpas.web.jsf.util.ComponentInformation;

public class UITree extends UIComponentPimpasBase {

	public static final String COMPONENT_TYPE				= ComponentInformation.COMPONENT_PREFIX_TYPE+".tree";
	public static final String COMPONENT_FAMILY				= ComponentInformation.COMPONENT_PREFIX_FAMILY+".tree";
	public static final String COMPONENT_RENDER_TYPE		= ComponentInformation.COMPONENT_PREFIX_RENDER+".tree";
	
	public static final String DEFAULT_BLANK_IMAGE			= "blank.png";
	public static final String DEFAULT_I_IMAGE				= "I.png";
	public static final String DEFAULT_L_IMAGE				= "L.png";
	public static final String DEFAULT_LMINUS_IMAGE			= "Lminus.png";
	public static final String DEFAULT_T_IMAGE				= "T.png";
	public static final String DEFAULT_TMINUS_IMAGE			= "Tminus.png";
	public static final String DEFAULT_TPLUS_IMAGE			= "Tplus.png";
	
	public static final String DEFAULT_CLOSED_BRANCH_ICON 	= "branch_closed.png";
	public static final String DEFAULT_OPENED_BRANCH_ICON	= "branch_opened.png";
	public static final String DEFAULT_LEAF_ICON			= "leaf.png";
	
	public static final String DEFAULT_COMPONENT_STYLE		= "pimpasTree";
	public static final String DEFAULT_COMPONENT_PATH 		= "tree/";
	
	private String onNodeRemoved;
	private String onNodeAdded;
	private String onNodeChanged;
	private String onChange;
	private String componentPath;
	private String title;
	
	@Override
	public Object saveState(FacesContext context) {
		Object[] ob = new Object[7];
		ob[0] = super.saveState(context);
		ob[1] = this.getOnNodeRemoved();
		ob[2] = this.getOnNodeAdded();
		ob[3] = this.getOnNodeChanged();
		ob[4] = this.getOnChange();
		ob[5] = this.getComponentPath();
		ob[6] = this.getTitle();
		
		return ob;
	}
	
	@Override
	public void restoreState(FacesContext context, Object state) {
		Object[] ob = (Object[]) state;
		super.restoreState(context, ob[0]);
		this.setOnNodeRemoved((String) ob[1]);
		this.setOnNodeAdded((String) ob[2]);
		this.setOnNodeChanged((String) ob[3]);
		this.setOnChange((String) ob[4]);
		this.setComponentPath((String) ob[5]);
		this.setTitle((String) ob[6]);
	}

	@Override
	public String getRendererType() {
		return COMPONENT_RENDER_TYPE;
	}

	@Override
	public String getFamily() {
		return COMPONENT_FAMILY;
	}

	public String getOnChange() {
		return onChange;
	}

	public void setOnChange(String onChange) {
		this.onChange = onChange;
	}

	public String getOnNodeAdded() {
		return onNodeAdded;
	}

	public void setOnNodeAdded(String onNodeAdded) {
		this.onNodeAdded = onNodeAdded;
	}

	public String getOnNodeChanged() {
		return onNodeChanged;
	}

	public void setOnNodeChanged(String onNodeChanged) {
		this.onNodeChanged = onNodeChanged;
	}

	public String getOnNodeRemoved() {
		return onNodeRemoved;
	}

	public void setOnNodeRemoved(String onNodeRemoved) {
		this.onNodeRemoved = onNodeRemoved;
	}

	public String getComponentPath() {
		return componentPath;
	}

	public void setComponentPath(String componentPath) {
		this.componentPath = componentPath;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}
}